-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tech debt: update ledger dependencies #346
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/shapeshift/hdwallet/5vJwgoA5rtMuU1bCqexW28VGfk9P [Deployment for 599f164 failed] |
@@ -9,16 +9,19 @@ | |||
"dev": "yarn parcel index.html", | |||
"clean": "rm -rf dist .cache" | |||
}, | |||
"engines": { | |||
"node": "14.x" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is accurate. You're 100% certain this doesn't run on older versions of node? I'm running node 12.x and it compiles fine for me.
@@ -13,6 +13,9 @@ | |||
"clean": "rm -rf dist tsconfig.tsbuildinfo", | |||
"prepublishOnly": "yarn clean && yarn build" | |||
}, | |||
"engines": { | |||
"node": "14.x" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is wrong because we use hdwallet in axiom which runs node 12. "engines" will prevent use of any other version of node. If you absolutely want to add "engines" then use ">= 12" or whatever the minimum version of node is that is compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove or change the engines
property in package.json
.
"engines": { | ||
"node": "14.x" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We removed engine restrictions on purpose several versions ago. If a dependency requires at least node 14, then it's own engines
block should be set; if it isn't, we should set it on the affected hdwallet-*
package, but it shouldn't be all-pervasive, and should at least specify >=14
instead of 14.x
.
@@ -10,19 +10,20 @@ import * as ledger from "@shapeshiftoss/hdwallet-ledger"; | |||
|
|||
const RECORD_CONFORMANCE_MOCKS = false; | |||
|
|||
function translateCoin(coin: string): { new (transport: Transport): Record<string, (...args: any[]) => unknown> } { | |||
return core.mustBeDefined(({ | |||
function translateCoin(coin: string): any | unknown { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any | unknown
is just any
, which probably isn't what's intended, and if it is it probably shouldn't be.
function translateCoin(coin: string): any | unknown { | |
function translateCoin(coin: string): äny! äny! Cthulhu fhtagn! { |
return { | ||
[core.BTCInputScriptType.SpendAddress]: "legacy", | ||
[core.BTCInputScriptType.CashAddr]: "legacy", | ||
[core.BTCInputScriptType.SpendWitness]: "bech32", | ||
[core.BTCInputScriptType.SpendP2SHWitness]: "p2sh", | ||
} as Partial<Record<core.BTCInputScriptType, string>>)[scriptType]); | ||
}[scriptType]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaves no runtime check that all core.BTCInputScriptType
options are accounted for. A switch statement without a default case would instead provide a static guarantee of full coverage -- though it would still need a default throw for forwards-compatibility. I'd argue it's too verbose, and a simple map and throw-if-undefined (a la core.mustBeDefined
) is preferable.
return { | |
[core.BTCInputScriptType.SpendAddress]: "legacy", | |
[core.BTCInputScriptType.CashAddr]: "legacy", | |
[core.BTCInputScriptType.SpendWitness]: "bech32", | |
[core.BTCInputScriptType.SpendP2SHWitness]: "p2sh", | |
} as Partial<Record<core.BTCInputScriptType, string>>)[scriptType]); | |
}[scriptType]; | |
switch (scriptType) { | |
case core.BTCInputScriptType.SpendAddress: | |
return "legacy"; | |
case core.BTCInputScriptType.CashAddr: | |
return "legacy"; | |
case core.BTCInputScriptType.SpendWitness: | |
return "bech32"; | |
case core.BTCInputScriptType.SpendP2SHWitness: | |
return "p2sh"; | |
} |
const keySet = msg.inputs[i].addressNList | ||
.map((num) => (num >= core.HARDENED ? `${num - core.HARDENED}'` : num)) | ||
.join("/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const keySet = msg.inputs[i].addressNList | |
.map((num) => (num >= core.HARDENED ? `${num - core.HARDENED}'` : num)) | |
.join("/") | |
const keySet = core.addressNListToBIP32(msg.inputs[i].addressNList).replace(/^m\//, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I originally coded but either the hot-reload failed to pick up my changes or I screwed up the regex and it wasn't working. I'll see if I can pull it off this time.
@@ -58,7 +58,7 @@ export function arrayify(value: string): Uint8Array { | |||
return new Uint8Array(result); | |||
} | |||
|
|||
const HARDENED = 0x80000000; | |||
export const HARDENED = 0x80000000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this would need a better name for export at this level; also it doesn't need to be exported if if you use core.addressNListToBIP32
as shown below.
export const HARDENED = 0x80000000; | |
const HARDENED = 0x80000000; |
|
||
const appName = _.get(networksUtil[core.mustBeDefined(core.slip44ByCoin(coin))], "appName"); | ||
if (!appName) { | ||
throw new Error(`Unable to find associated app name for coin: ${coin}`); | ||
} | ||
|
||
const res = await this.transport.call(null, "getAppAndVersion"); | ||
handleError(res, this.transport); | ||
|
||
const { | ||
payload: { name: currentApp }, | ||
} = res; | ||
if (currentApp !== appName) { | ||
throw new core.WrongApp("Ledger", appName); | ||
if (currentApp !== coin) { | ||
throw new core.WrongApp("Ledger", coin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ledger app names do not equal hdwallet-core
's Coin
names. Note for example BitcoinCash
vs Bitcoin Cash
and Digibyte
vs DigiByte
. I don't think you can avoid a lookup of some kind here.
return core.mustBeDefined(({ | ||
function translateMethod(method: string): (transport: Transport, ...args: any[]) => any { | ||
return ({ | ||
decorateAppAPIMethods: TransportWebUSB.decorateAppAPIMethods, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a static method -- does this work at runtime?
@@ -14,7 +14,7 @@ import { | |||
handleError, | |||
} from "./utils"; | |||
|
|||
const supportedCoins = ["Testnet", "Bitcoin", "BitcoinCash", "Litecoin", "Dash", "DigiByte", "Dogecoin"]; | |||
export const supportedCoins = ["Testnet", "Bitcoin", "BitcoinCash", "Litecoin", "Dash", "DigiByte", "Dogecoin"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This export is not needed since btcSupportsCoin is already available.
319c09d
to
599f164
Compare
599f164
to
319c09d
Compare
(whoops, wrong branch!) |
@millsmcilroy I did some cleanup on this and added the TS magic needed to pull in the types from the ledger packages. It needed a couple of supporting PRs (#349, #350) to enable strict mode first; since we use I opened #351 separately to avoid clobbering your branch history with the extra strict-mode stuff, but if you like it IMO it'd make more sense to force-push it to this branch and use this PR instead of that one. |
Closing in favor of #351 |
Also removes u2f which Ledger has deprecated